const SALT = 'pro250523'

function getSecretKey() {
  return CryptoJS.MD5(SALT).toString()
}

export function toKeysLocal(str) {
  const secretKey = getSecretKey()
  const encrypted = CryptoJS.AES.encrypt(str, secretKey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
    noSalt: true
  })
  return encrypted.toString()
}

export function decryptLocal(str) {
  try {
    const secretKey = getSecretKey()
    const bytes = CryptoJS.AES.decrypt(str, secretKey, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
      noSalt: true
    })
    const decryptedData = bytes.toString(CryptoJS.enc.Utf8)
    return decryptedData
  } catch (error) {
    console.error('解密失败:', error)
    return null
  }
}

const encrypt = toKeysLocal(666)
console.log(decryptLocal(encrypt))
